﻿
Namespace PL.CoreSDK
    Public Class SOPRevision_PL
        Inherits PLBase
        'mplements IPLProcess

        Private _aQueryName As String

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
            _aQueryName = queryName
        End Sub

        Public Overrides Sub ValidateRow(row As DataRow)
            row.ClearErrors()

            'If row.Table.Columns.Contains("TypeId_FK") Then
            '    If IsDBNull(row("TypeId_FK")) Then
            '        row.SetColumnError("TypeId_FK", "Mandatory")
            '    End If
            'End If
            '

            '
            If row.HasErrors Then
                row.RowError = "Please check your columns, a validation error occur"
            End If
        End Sub

        Public Overrides Function Delete() As Boolean
            'Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            'Throw New NotImplementedException("Validate To Come...")
            Return True
        End Function

        Public Shared Function CreateNewSOPRevision(ByVal SOPId As Guid) As Boolean
            Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing

            Try
                sqlcmd = MetaQuery.GetSPCmdByMetaName("SOPRevision_Update")

                sqlcmd.Parameters("@SOPRevisionId").Value = Nothing
                sqlcmd.Parameters("@SOPId_FK").Value = SOPId
                sqlcmd.Parameters("@RevisionNumber").Value = Nothing
                sqlcmd.Parameters("@RevisionDate").Value = Date.Today
                sqlcmd.Parameters("@IsActivated").Value = 0
                sqlcmd.Parameters("@ActivatedDate").Value = Nothing
                sqlcmd.Parameters("@StatusID_FK").Value = Nothing

                sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)
            Catch ex As Exception
                Throw ex
            Finally
                If sqlcmd IsNot Nothing Then
                    sqlcmd.Dispose()
                End If
            End Try
            Return True
        End Function

        Public Shared Function GetSOPRevisionByID(ByVal id As Guid) As DataRow
            Dim aRow As DataRow = MetaQuery.GetDataById("SOPRevision", id)
            Return aRow
        End Function
    End Class
End Namespace
